#include<bits/stdc++.h>
using namespace std;

struct node {
	int x, y, pre;
};

int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int a[10][10];
bool vis[10][10];

node path[1000];

void Write(int x) {
	if (path[x].pre != -1) {
		Write(path[x].pre);
	}
	printf("(%d, %d)\n", path[x].x - 1, path[x].y - 1);
}

void bfs() {
	int father = 1, child = 2;
	queue<node> q;
	q.push({1, 1, -1});
	vis[1][1] = 1;

	while (!q.empty()) {
		node t = q.front();
		q.pop();
		path[father++] = t;

		if (t.x == 5 && t.y == 5)
			Write(father - 1);

		for (int i = 0; i < 4; i++) {
			int xx = t.x + dx[i];
			int yy = t.y + dy[i];
			if (xx > 0 && xx <= 5 && yy > 0 && yy <= 5 && !vis[xx][yy] && a[xx][yy] == 0) {
				q.push({xx, yy, father - 1});
				vis[xx][yy] = 1;
				path[child++] = {xx, yy, father - 1};
			}
		}
	}
}

int main() {
	for (int i = 1; i <= 5; i++)
		for (int j = 1; j <= 5; j++)
			scanf("%d", &a[i][j]);
	bfs();
	cout << endl;
	system("pause");
	return 0;
}

